package com.example.mybatis.plugin;

import java.util.ArrayList;
import java.util.List;

public class InterceptorChain {
    private final List<Interceptor>  interceptors = new ArrayList<>();
    public synchronized  InterceptorChain add(Interceptor interceptor){
        interceptors.add(interceptor);
        return  this;
    }
    public synchronized  InterceptorChain add(List<Interceptor> interceptor){
        for (Interceptor interceptorOne:interceptors){
            this.add(interceptorOne);
        }
        return  this;
    }
    public Object pluginAll(Object target){
        for (Interceptor interceptor : interceptors){
      target = DefaultInvocationHandler.proxy(target,interceptor);
        }
        return  target;
    }
}
